package com.ht.base.system.biz.convert;

import com.ht.base.system.common.pojo.bo.SysDictTypeBO;
import com.ht.base.system.dao.domain.SysDictTypeDO;
import org.base.common.appexception.AppErrorCodeEnum;
import org.base.common.appexception.AppException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类SysDictTypeBeanUtil.java的实现描述：字典类型表工具类
 * 
 * @Author hdengxian
 * @Date 2023年05月24日
 */
public class SysDictTypeBeanUtil {

    private SysDictTypeBeanUtil(){
    }

    public static SysDictTypeDO sysDictTypeBOToDO(SysDictTypeBO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysDictTypeDO targetObj = new SysDictTypeDO();
        /**字典主键**/
        targetObj.setId(srcObj.getSysDictTypeId());
        /**字典类型**/
        targetObj.setDictType(srcObj.getDictType());
        /**字典名称**/
        targetObj.setDictName(srcObj.getDictName());
        /**状态（0正常 1停用）**/
        targetObj.setStatus(srcObj.getStatus());
        /**创建者**/
        targetObj.setCreateBy(srcObj.getCreateBy());
        /**创建时间**/
        targetObj.setCreateTime(srcObj.getCreateTime());
        /**更新者**/
        targetObj.setUpdateBy(srcObj.getUpdateBy());
        /**更新时间**/
        targetObj.setUpdateTime(srcObj.getUpdateTime());
        /**备注**/
        targetObj.setRemark(srcObj.getRemark());
        return targetObj;
    }

    public static SysDictTypeBO sysDictTypeDOToBO(SysDictTypeDO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysDictTypeBO targetObj = new SysDictTypeBO();
        /**字典主键**/
        targetObj.setSysDictTypeId(srcObj.getId());
        /**字典类型**/
        targetObj.setDictType(srcObj.getDictType());
        /**字典名称**/
        targetObj.setDictName(srcObj.getDictName());
        /**状态（0正常 1停用）**/
        targetObj.setStatus(srcObj.getStatus());
        /**创建者**/
        targetObj.setCreateBy(srcObj.getCreateBy());
        /**创建时间**/
        targetObj.setCreateTime(srcObj.getCreateTime());
        /**更新者**/
        targetObj.setUpdateBy(srcObj.getUpdateBy());
        /**更新时间**/
        targetObj.setUpdateTime(srcObj.getUpdateTime());
        /**备注**/
        targetObj.setRemark(srcObj.getRemark());
        return targetObj;
    }

    public static List<SysDictTypeBO> doList2BOList(List<SysDictTypeDO> doList) {
        List<SysDictTypeBO> boList = new ArrayList<>();
        if (CollectionUtils.isEmpty(doList)) return boList;

        doList.stream().forEach(d -> boList.add(SysDictTypeBeanUtil.sysDictTypeDOToBO(d)));
        return boList;
    }

    public static List<SysDictTypeDO> boList2DOList(List<SysDictTypeBO> boList) {
        List<SysDictTypeDO> doList = new ArrayList<>();
        if (CollectionUtils.isEmpty(boList)) return doList;

        boList.stream().forEach(b -> doList.add(SysDictTypeBeanUtil.sysDictTypeBOToDO(b)));
        return doList;
    }

    public static void insertCheckParam(SysDictTypeBO dictTypeBO) {
        if (dictTypeBO == null) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(dictTypeBO.getDictType())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(dictTypeBO.getDictName())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(dictTypeBO.getStatus())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
    }
}